import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import javax.swing.JOptionPane;


/**
 * To create test files
 * 
 * @author root
 * 
 */
public class MyFile implements Runnable {
	/**
	 * Pointer of GrayScale class
	 */
	private GrayScale grey;
	/**
	 * Start index of NNET array
	 */
	private int indice;
	/**
	 * End index of NNET array
	 */
	private int max;
	/**
	 * Number of file ( you can have more )
	 */
	private int name;

	/**
	 * 
	 * @param name
	 *           file name
	 * @param grey
	 *           pointer of GrayScale class
	 * @param indice
	 *           start index
	 * @param max
	 *           end index
	 */
	public MyFile(int name, GrayScale grey, int indice, int max) {
		this.name = name;
		this.grey = grey;
		this.indice = indice;
		this.max = max;

	}

	@Override
	public void run() {
		File fileSave = new File("myTest" + name + ".txt");
		try {
			fileSave.createNewFile();
			try {
				FileWriter fw = new FileWriter(fileSave);
				BufferedWriter bw = new BufferedWriter(fw);
				PrintWriter outFile = new PrintWriter(bw);

				outFile.print(((max - indice)) + "\n");
				for (int i = 0; i < max - indice; i++) {
					outFile.append(grey.nnet[indice + i] + "\n");
				}

				try {
					Thread.sleep(200);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				outFile.close();
			} catch (IOException e) {
				JOptionPane.showMessageDialog(null, "Errore scrittura test");
				e.printStackTrace();
			}
		} catch (IOException e1) {
			JOptionPane.showMessageDialog(null, "Errore creazione test");
			e1.printStackTrace();
		}

		grey.done();

	}

}
